package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/22 14:33
 * 用户管理员界面接口
 */
@Api(tags = "用户管理员界面接口")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

  @Autowired
  private UserInfoService userInfoService;

  //分页获取用户列表
  @ApiOperation(value = "分页获取用户列表")
  @GetMapping("{page}/{limit}")
  public Result userList(@PathVariable Long page, @PathVariable Long limit, UserInfoQueryVo userInfoQueryVo) {
    Page<UserInfo> pageParam = new Page<>(page,limit);
    return Result.ok(userInfoService.getUserInfoList(pageParam,userInfoQueryVo));
  }

  // 用户的锁定与解锁
  @ApiOperation(value = "用户的锁定与解锁")
  @GetMapping("lock/{userId}/{status}")
  public Result lock(@PathVariable Long userId,@PathVariable Integer status) {
    userInfoService.userLock(userId,status);
    return Result.ok();
  }

  // 用户的详情
  @GetMapping("show/{userId}")
  public Result userShow(@PathVariable Long userId) {
    Map<String,Object> map = userInfoService.userDetail(userId);
    return Result.ok(map);
  }

  //认证审批
  @ApiOperation(value = "认证审批")
  @GetMapping("approval/{userId}/{authStatus}")
  public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus){
    userInfoService.approval(userId,authStatus);
    return Result.ok();
  }

}
